/**
 * @properties={typeid:35,uuid:"A226A7CA-77FF-4A4E-9F09-0ED4678F4912",variableType:4}
 */
var found = null;

/** Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"C0120C33-BB17-466C-B292-4D84FAA75B5B"}
 */
function buscar_pendientes() 
{	
	globals.gtotal_saldo = 0
	// para traer solamente los que tienen saldo y son debito  
	if (globals.marca_primer_find == 0)
	{
	globals.marca_primer_find=1
	var estado=forms.ctacte_pr_list_opago.controller.find()
	//forms.ctacte_pr_list_opago.saldo > 0  no dad error
	forms.ctacte_pr_list_opago.saldo = '> 0'
	forms.ctacte_pr_list_opago.ctacte_pr_to_tab_mov_pr.d_h=2 //contrario a ventas ?	
	forms.ctacte_pr_list_opago.proveedor_id=forms.opago_1.proveedor_id
	found = forms.ctacte_pr_list_opago.controller.search()
	
	if (found <= 0)
	{
		globals.gMensaje="No hay mov. de ctacte con saldo"
		globals.gMensajes
	}
	}
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"8F36CEC1-CF82-434B-93D2-94E610307CA3"}
 */
function confirmar_seleccion() 
{
	//borrar  lo que tenga en op_detalle_comprob 
	forms.opago_1.op_cabecera_to_op_detalle_comprob.deleteAllRecords()
	
	//otra recorrida como la anterior para los marcados = 1
	found=forms.ctacte_pr_list_opago.controller.getMaxRecordIndex()	
	if (found > 0)
	{
	globals.gtotal_comprob=0 
	var aux_saldo=0 // 02/07/2010 para que considere signo del movto
	for (var i = 1 ; i <= forms.ctacte_pr_list_opago.controller.getMaxRecordIndex(); i++)
	 {		 
	  forms.ctacte_pr_list_opago.controller.setSelectedIndex(i)
	  if (forms.ctacte_pr_list_opago.marcado_ctacte==1)
	  {
	//grabar lo que marcado en detalle_comprob
	  forms.opago_1.op_cabecera_to_op_detalle_comprob.newRecord()
	  //  llenar datos
	  forms.opago_1.op_cabecera_to_op_detalle_comprob.cod_mov=cod_mov
	  forms.opago_1.op_cabecera_to_op_detalle_comprob.fecha=fecha_mov
	  forms.opago_1.op_cabecera_to_op_detalle_comprob.importe=saldo
	  forms.opago_1.op_cabecera_to_op_detalle_comprob.imp_original=importe
	  forms.opago_1.op_cabecera_to_op_detalle_comprob.nro_comprobante=nro_factura
	  forms.opago_1.op_cabecera_to_op_detalle_comprob.letra=letra
	  forms.opago_1.op_cabecera_to_op_detalle_comprob.sucursal=sucursal
	  // agregado porque no podia desmarcar ctacte en opago_1
	  forms.opago_1.op_cabecera_to_op_detalle_comprob.ctacte_pr_id=ctacte_pr_id
	  // 02/07/2010 para que considere signo del movto
	  if (ctacte_pr_to_tab_mov_pr.d_h == 1)
	 	{
		  	aux_saldo = globals.redondeo(saldo * (-1))
	  	}
	  else
	  	{
		  	aux_saldo = globals.redondeo(saldo) 
	  	} 
	  globals.gtotal_comprob+=aux_saldo
	  }
	 }
	}
	
	// por final todo ok hacer close del form
	application.closeFormDialog('ctacte_opago')
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"7488248D-BB4E-4B23-A2D3-B02CF1E39314"}
 */
function marcar_todo() 
{
	for (var i = 1 ; i <= forms.ctacte_pr_list_opago.controller.getMaxRecordIndex(); i++)
	 {		 
	  forms.ctacte_pr_list_opago.controller.setSelectedIndex(i)
	  forms.ctacte_pr_list_opago.marcado_ctacte=1
	 }
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"961675D8-2499-40BE-B783-529A6C8C6152"}
 */
function desmarcar_todo() 
{
	for (var i = 1 ; i <= forms.ctacte_pr_list_opago.controller.getMaxRecordIndex(); i++)
	 {		 
	  forms.ctacte_pr_list_opago.controller.setSelectedIndex(i)
	  forms.ctacte_pr_list_opago.marcado_ctacte=0
	 }
}
